//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "stdafx.h"
#include "ioctl.h"
#include "pm.h"
#include "..\\WBTCMNPRPG\\Display_VIA.h"

void 
TestDesktopResolution()
{
	// OEM-specific code goes here.
}

BOOL IsSupportedPowerOFF(void)
{

	BOOL rez = FALSE;
	HKEY hKey;

	if ( 0 == RegOpenKeyEx(HKEY_LOCAL_MACHINE, VIA_IS_SUPPORTED,0,0, &hKey) )
	{
		rez = TRUE;
	}

	if ( hKey != NULL )
	{
		//CloseRegistryKey(hKey);
		RegCloseKey(hKey);
	}

	return rez;
}

#define PWM_IOCTL_POWEROFF      0x1001

void PowerOFFTerminal(void)
{
	if ( IsSupportedPowerOFF() )
	{
//		SetSystemPowerState(NULL, POWER_STATE_OFF, POWER_FORCE);
		SetSystemPowerState(NULL, POWER_STATE_SUSPEND, POWER_FORCE);
	} else {
		SetSystemPowerState(NULL, POWER_STATE_RESET, POWER_FORCE);
	}
}

void RestartTerminal(void)
{
	// OEM-specific code goes here.

	SetSystemPowerState(NULL, POWER_STATE_RESET, POWER_FORCE);
/*
	BOOL bRetVal;
	DWORD dwBytesReturned;
	
	RETAILMSG(1,(TEXT("Before KernelIoControl in ioctl.cpp \r\n")));
	bRetVal = KernelIoControl(IOCTL_HAL_REBOOT,NULL,0,NULL, 
		NULL, &dwBytesReturned);

	if ( bRetVal == FALSE)
	{
		RETAILMSG(1,(TEXT("KernelIoControl call for Reboot failed !!!!!! \r\n")));
	}
*/
}

// fetches the UUID for the device
BOOL
GetUUID( GUID* myUUID)
{
	BOOL bRetVal = FALSE;
	DWORD dwBytesReturned = 0;
	DWORD SPI = SPI_GETUUID;
	
	bRetVal = KernelIoControl(IOCTL_HAL_GET_DEVICE_INFO, &SPI, sizeof(DWORD), myUUID, sizeof(GUID), &dwBytesReturned);
	if (!bRetVal) 
	{
        //RETAILMSG(1,(TEXT("KernelIoControl call failed!\r\n")));
	}

	return bRetVal;
}